package com.young.cms.model.gen4;

import com.young.cms.model.enums.EControlCheckEnum;
import com.young.common.util.CommonUtil;

/**
 * 校验规则单项
 *
 * @author wangjy
 * @date 2022/04/02 10:59:09
 */
public class CheckRuleItem {
    /**
     * 校验类型
     *
     * @see EControlCheckEnum
     */
    private String checkType;
    /**
     * 正则表达式
     */
    private String checkReg;
    /**
     * 错误提示
     */
    private String errorTips;
    /**
     * 最小值
     */
    private Integer min;
    /**
     * 最大值
     */
    private Integer max;

    /**
     * 构造校验项
     *
     * @param controlCheckEnum
     * @param genColV4
     * @return
     */
    public static CheckRuleItem build(EControlCheckEnum controlCheckEnum, GenColV4 genColV4) {
        CheckRuleItem checkRuleItem = new CheckRuleItem();
        checkRuleItem.setCheckType(controlCheckEnum.getType());
        String error;
        if (EControlCheckEnum.ErrEmpty == controlCheckEnum) {
            error = String.format("%s不允许为空", CommonUtil.getDefaultValue(genColV4.getControlTitle(), genColV4.getFieldRemark()));
        } else if (EControlCheckEnum.ErrLength == controlCheckEnum) {
            checkRuleItem.setMin(1);
            checkRuleItem.setMax(genColV4.getFieldLength());
            error = String.format("%s内容长度限制为%s~%s", CommonUtil.getDefaultValue(genColV4.getControlTitle(), genColV4.getFieldRemark()), checkRuleItem.getMin(), checkRuleItem.getMax());
        } else if (EControlCheckEnum.ErrNumber == controlCheckEnum) {
            error = String.format("%s请输入数字类型", CommonUtil.getDefaultValue(genColV4.getControlTitle(), genColV4.getFieldRemark()));
        } else if (EControlCheckEnum.ErrMail == controlCheckEnum) {
            error = String.format("%s请输入正确的邮箱格式", CommonUtil.getDefaultValue(genColV4.getControlTitle(), genColV4.getFieldRemark()));
        } else if (EControlCheckEnum.ErrPhone == controlCheckEnum) {
            error = String.format("%s请输入正确的手机号格式", CommonUtil.getDefaultValue(genColV4.getControlTitle(), genColV4.getFieldRemark()));
        } else if (EControlCheckEnum.ErrReg == controlCheckEnum) {
            error = String.format("%s请输入正确的手机号格式", CommonUtil.getDefaultValue(genColV4.getControlTitle(), genColV4.getFieldRemark()));
        } else {
            error = "Error";
        }
        checkRuleItem.setErrorTips(error);
        return checkRuleItem;
    }

    public String getCheckType() {
        return checkType;
    }

    public void setCheckType(String checkType) {
        this.checkType = checkType;
    }

    public String getCheckReg() {
        return checkReg;
    }

    public void setCheckReg(String checkReg) {
        this.checkReg = checkReg;
    }

    public String getErrorTips() {
        return errorTips;
    }

    public void setErrorTips(String errorTips) {
        this.errorTips = errorTips;
    }

    public Integer getMin() {
        return min;
    }

    public void setMin(Integer min) {
        this.min = min;
    }

    public Integer getMax() {
        return max;
    }

    public void setMax(Integer max) {
        this.max = max;
    }
}
